/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.xtd.view.admin;

import com.xtd.facade.admin.XtdgroupFacade;
import com.xtd.model.admin.Xtdgroup;
import java.util.HashMap;
import java.util.Map;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;
import javax.faces.convert.FacesConverter;

/**
 *
 * @author Lu Yuanbin
 */
@FacesConverter(forClass = Xtdgroup.class)
public class XtdgroupConverter implements Converter {

    private static Map<String, Xtdgroup> cache = new HashMap<String, Xtdgroup>();

    @Override
    public Object getAsObject(FacesContext context, UIComponent component, String value) {

        if (value.trim().equals("")) {
            return null;
        } else {
            return cache.get(value);
        }
    }

    @Override
    public String getAsString(FacesContext context, UIComponent component, Object value) {
        if (value == null) {
            return null;
        } else {
            Xtdgroup xtdgroup  = (Xtdgroup) value;
            cache.put(xtdgroup.getName(), xtdgroup);
            return String.valueOf(xtdgroup.getName());
        }
    }
}
